<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/lib/layui-v2.5.5/css/modules/layer/default/layer.css"/> 
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        #sku-wrap, #sku-value-wrap{
            display: flex;
            align-items: start;
            float: left;
        }
        #sku-wrap input,#sku-value-wrap input{
            background: transparent;
            width: 60px;
            text-align: center;
            border: 1px solid #E6E6E6;
            margin-right: 20px;
            border-radius: 2px;
            padding: 10px 0;
        }
        #sku-wrap .sku-active{
            border: 1px solid #1F9FFF;
            color: #1F9FFF;
        }
        
        #my-table{
            display: none;
            margin-left: 94px;
        }
        #my-table input{
            border: 0;
        }
        #my-table td{
            white-space: nowrap;
        }
        .layui-form-item{
            width: 100%;
        }
        .delete-icon{
            display: inline-block;
            width: 12px;
            height: 1px;
            background: #C2C2C2;
            transform: rotate(45deg);
            -webkit-transform: rotate(45deg);
            position: relative;
            right: 33px;
            top: 5px;
            cursor: pointer;
            z-index: 9999;
        }
        .delete-icon:after{
            content: '';
            display: block;
            width: 12px;
            height: 1px;
            background: #C2C2C2;
            transform: rotate(-90deg);
            -webkit-transform: rotate(-90deg);
            cursor: pointer;
            position: relative;
            z-index: 9999;
        }
        .imgs{
            width: 700px;
            height: 500px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>表单集合演示</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" method="post" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">模块名</label>
                <div class="layui-input-block">
                    <input value="{{$row->name??''}}" type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入模块名" class="layui-input">
                </div>
            </div>
            
            <div id="from" class="layui-form"  style="padding: 0px;">
                <div class="layui-form-item" style="display: flex;">
                    <label class="layui-form-label" style="min-width: 80px;">规格</label>
                    <div id="sku-wrap">
                    @if(!empty($row->add_html))
                        <?php echo $row->add_html; ?>
                    @else
                        <input type="button" class="sku sku-active ShiJian " value="时间">
                        <span class="delete-icon"></span>
                    @endif
                    </div>
                    <div class="layui-input-inline" id="skuModel" style="display: none;border: 1px solid #E6E6E6;padding: 20px;margin-right: 0;min-width: 190px;">
                        <input type="text" name="skuName" id="skuName"  class="layui-input" placeholder="请输入规格名" style="margin-bottom: 20px;" autocomplete="off">
                        <input type="button" class="layui-btn layui-btn-normal" id="skuConfirm" value="确认">
                        <input type="button" class="layui-btn layui-btn-danger" id="skuCancel" value="取消">
                    </div>
                    <div class="" style="">
                        <input name="id" type="hidden" class="layui-btn" id="" value="{{$row->hidden??''}}">
                    </div>
                    <div class="layui-input-inline" style="width: 64px;">
                        <input type="button" class="layui-btn" id="skuAdd" value="添加">
                    </div>
                </div>
                <div class="layui-form-item" style="clear: none;float: left">
                    <label class="layui-form-label"><span id="fuzhi"></span>赋值</label>
                    <div id="sku-value-wrap">
                        @if(!empty($row->add2_html))
                        <?php echo $row->add2_html??'';?>
                        @else
                        <input type="text" class="sku-value 8:00" style="display: none;" name="ShiJian" value="8:00" readonly="">
                        <span value="8:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 8:30" style="display: none;" name="ShiJian" value="8:30" readonly="">
                        <span value="8:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 9:00" style="display: none;" name="ShiJian" value="9:00" readonly="">
                        <span value="9:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 9:30" style="display: none;" name="ShiJian" value="9:30" readonly="">
                        <span value="9:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 10:00" style="display: none;" name="ShiJian" value="10:00" readonly="">
                        <span value="10:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 10:30" style="display: none;" name="ShiJian" value="10:30" readonly="">
                        <span value="10:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 11:00" style="display: none;" name="ShiJian" value="11:00" readonly="">
                        <span value="11:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 11:30" style="display: none;" name="ShiJian" value="11:30" readonly="">
                        <span value="11:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 12:00" style="display: none;" name="ShiJian" value="12:00" readonly="">
                        <span value="12:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 12:30" style="display: none;" name="ShiJian" value="12:30" readonly="">
                        <span value="12:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 13:00" style="display: none;" name="ShiJian" value="13:00" readonly="">
                        <span value="13:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 13:30" style="display: none;" name="ShiJian" value="13:30" readonly="">
                        <span value="13:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 14:00" style="display: none;" name="ShiJian" value="14:00" readonly="">
                        <span value="14:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 14:30" style="display: none;" name="ShiJian" value="14:30" readonly="">
                        <span value="14:30" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 15:00" style="display: none;" name="ShiJian" value="15:00" readonly="">
                        <span value="15:00" class="delete-icon" style="display: none;"></span>
                        <input type="text" class="sku-value 15:30" style="display: none;" name="ShiJian" value="15:30" readonly="">
                        <span value="15:30" class="delete-icon" style="display: none;"></span>
                        @endif
                    </div>
                    <div class="layui-input-inline" id="skuValueModel" style="display: none;border: 1px solid #E6E6E6;padding: 20px;margin-right: 0;min-width: 190px;">
                        <input type="text" name="skuValueName" id="skuValueName"  class="layui-input" placeholder="请输入规格值" style="margin-bottom: 20px;" autocomplete="off">
                        <input type="button" class="layui-btn layui-btn-normal" id="skuValueConfirm" value="确认">
                        <input type="button" class="layui-btn layui-btn-danger" id="skuValueCancel" value="取消">
                    </div>
                    <div class="layui-input-inline" style="width: 64px;">
                        <input type="button" class="layui-btn" id="skuValueAdd" value="添加">
                    </div>
                </div>
                <!-- <div class="layui-form-item" style="clear: none;float: left">
                    <div class="layui-card-body" id="my-table">
                        <table class="layui-table">
                            <thead>
                            <tr id="th">
                            </tr>
                            </thead>
                            <tbody id="tbody">
                            </tbody>
                        </table>
                    </div>
                </div> -->
            </div>
            <input type="button" class="layui-btn" id="huoqu" value="生成添加规格表格">
            <!-- ssksskssk -->
            <div id="sku" data-item='' data-data=""></div>
            <div class="layui-form-item" pane>
                <label class="layui-form-label">结果</label>
                <div class="layui-input-block" id="data-html" style="padding:20px;"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a class="layui-btn" id="_get">获取数据</a>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="tijiao" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            
        </form>


<script src="/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<!-- <script src="/static/lib/layui-v2.5.5/lay/layui.js" charset="utf-8"></script> -->
<script src="/js/jquery.min.js"></script>
<!-- <script src="/js/layui.js"></script> -->
<script>
    
    // function dian(){
    // ssk = $("#img").val();
    // // $("#imgs").css({"display":""});
    // alert(ssk);
    // $.post("/houtai/index/img_ok",{ssk},function(img_bool){

    // });
    // // $(".xianshi").attr("src",);
    // }   
    layui.use(['upload','form', 'layer'],function() {
			var laydate = layui.laydate;
			$ = layui.jquery
			,upload = layui.upload;
			var form = layui.form,
			layer = layui.layer;
			//监听提交
			form.on('submit(add)',
			function(data) {
				console.log(data);
				//发异步，把数据提交给php
				$.ajax({
				  type:'POST',
				  dataType:'json',
				  data:data.field,
				  url:'{:url("houtai/add_ok")}',
				  success:function(msg){
					if(msg.code==200){
						 layer.alert(msg.msg, {
							  icon: 6
						  },
						  function() {
							  //关闭当前frame
							  xadmin.close();
							  // 可以对父窗口进行刷新 
							  xadmin.father_reload();
						  });
					}else{
					  layer.msg(msg.msg, {icon: 5})
					}
				  },
				  error:function(msg){
					 layer.msg('网络错误', { icon:5});
				  }
				})
				return false;
			});
			//普通图片上传
			var uploadInst = upload.render({
			  elem: '#test1',
			  url: '{:url("houtai/index/vod_upload")}',
			  multiple: false, //开启多图上传这个是重点
			  accept: 'images', // 允许上传的文件类型
			  size: 2048,  //允许大小，最大2M
			  field:'vod_img',
			  before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, per_img, result){
				  $('#demo1').attr('src', result); //图片链接（base64）
				});
			  }
			  ,done: function(res){
				console.log(res.vod_img)
				//如果上传失败
			   $('#vod_img111').val(res.vod_img)
				if(res.code == 1){
                    $('#img_xian').attr('style','');
                    return layer.msg('上传成功');
				}
				
				//上传成功
			  }
			  ,error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
				  uploadInst.upload();
				});
			  }
			});
 
		});
</script>
<!-- 规格 -->
<!-- <script src="/js/layer.js" type="text/javascript" charset="utf-8"></script> -->
<script src="/js/Convert_Pinyin.js"></script>
		    <script type="text/javascript">
		        $(document).ready(function(){
		            $('#sku-wrap').on('click', '.delete-icon', function (e) {
		                console.log('delete-icon');
		                event.stopPropagation();    //  阻止事件冒泡
		                var skuName = $(this).prev().val();
		                var fullName = pinyin.getFullChars(skuName);
		                var arrayzi = [];
						$("input[name="+fullName+"]").each(function(){
							var zi = $(this).val();
							arrayzi.push(zi);
						});
                        console.log(arrayzi);
		                for(var i = 0;i<arrayzi.length*2;i++){
		                    // $("input[value="+arrayzi[i]+"]").prev().remove();
							$("*[value="+arrayzi[i]+"]").remove();
		                    console.log(arrayzi[i]);
		                }
                        // var objs = document.getElementsByName(fullName);
		                // console.log(objs);
		                // for(var i = 0;i<=objs.length;i++){
		                //     objs[i].nextSibling.remove();
		                //     objs[i].remove();
		                //     console.log(i)
		                // }
		                $(this).prev().remove();
		                $(this).remove();
		
		                event.stopPropagation();    //  阻止事件冒泡
		                combination();
		            });
		            $('#sku-value-wrap').on('click', '.delete-icon', function (e) {
		                $(this).prev().remove();
		                $(this).remove();
		
		                event.stopPropagation();    //  阻止事件冒泡
		                combination();
		            });
		        });
		
		        var firstTime = false;
		        // 添加规格按钮
		        $('#skuAdd').click(function () {
		            var skeLen = $('#sku-wrap').children().length;
		            if(skeLen==0){
		                firstTime = true;
		            }else {
		                firstTime = false;
		            }
		            $(this).hide();
		            $('#skuModel').show();
		        });
		        //  取消添加规格按钮
		        $('#skuCancel').click(function () {
		            $('#skuName').val('');
		            $('#skuModel').hide();
		            $('#skuAdd').show();
		        });
		
		        //  添加规格确认按钮
		        var fullName = '';
		        $('#skuConfirm').click(function () {
		
                    
		            var skuName = $('#skuName').val();
		            if(skuName == ''){
		                layer.msg('请输入规格名');
		                return;
		            }
		            //获取全写拼音（调用js中方法）
		            fullName = pinyin.getFullChars(skuName);
		            //  判断规格是否已存在
		            if(ifSkuExit(fullName)){
		                layer.msg('此规格已存在！');
		                return;
		            }
		            if(firstTime){
		                $('#sku-wrap').append('<input type="button" class="sku sku-active sku-choose '+fullName+' " value="'+skuName+'"><span class="delete-icon"></span>');
		            }else{
		                $('#sku-wrap').append('<input type="button" class="sku '+fullName+' " value="'+skuName+'"><span class="delete-icon"></span>');
		            }
		            $('#skuName').val('');
		            $('#skuModel').hide();
					$('#skuAdd').show();
                    var arrayssks = [];
					$(".sku-choose").each(function(){
						var rew = $(this).val();
						arrayssks.push(rew);
					});
                    $("#fuzhi").text(arrayssks);
					
		        });
		
		        //  切换sku
		        $(document).on('dblclick', '.sku', function(){
		            console.log('sku');
		            event.stopPropagation();    //  阻止事件冒泡
		            $('.sku-value').hide();
		            $('#sku-value-wrap .delete-icon').hide();
		            if($(this).hasClass('sku-active')){
		                $(this).removeClass('sku-active');
		            }else {
		                var obj = $('.sku-active');
		                // if (obj.length==2){
		                //     layer.msg('只能选择两种规格');
		                //     return;
		                // }
		                $(this).addClass('sku-active');
		            }
		            $(this).addClass('sku-choose').siblings().removeClass('sku-choose');
		            var skuName = $(this).val();
		            fullName = pinyin.getFullChars(skuName);
		            console.log(fullName);
		            var objs = document.getElementsByName(fullName);
                    var arrayzi = [];
						$("input[name="+fullName+"]").each(function(){
							var zi = $(this).val();
							arrayzi.push(zi);
						});
		            for(var i =0;i<objs.length;i++){
		                $("*[value="+arrayzi[i]+"]").css('display','block');
		                // objs[i].nextSibling.style.display="block";
		            }
		            combination();
		        });
				
				$(document).on('click', '.sku', function(){
		            // console.log('sku');
		            event.stopPropagation();    //  阻止事件冒泡
		            $('.sku-value').hide();
		            $('#sku-value-wrap .delete-icon').hide();
		            if($(this).hasClass('sku-active')){
		                // $(this).removeClass('sku-active');
		            }else {
		                // var obj = $('.sku-active');
		                // if (obj.length==2){
		                //     layer.msg('只能选择两种规格');
		                //     return;
		                // }
		                // $(this).addClass('sku-active');
		            }
		            $(this).addClass('sku-choose').siblings().removeClass('sku-choose');
		            var skuName = $(this).val();
		            fullName = pinyin.getFullChars(skuName);
		            var objs = document.getElementsByName(fullName);
		            console.log(objs.length);
                    var arrayzi = [];
						$("input[name="+fullName+"]").each(function(){
							var zi = $(this).val();
							arrayzi.push(zi);
						});
		            for(var i =0;i<objs.length;i++){
		                $("*[value='"+arrayzi[i]+"']").css('display','block');
		                // objs[i].nextSibling.style.display="block";
		            }
		            combination();
		        });
		
		        // 添加规格值按钮
                
		        $('#skuValueAdd').click(function () {
                    
		            var skeLen = $('#sku-wrap').children().length;
		            if(skeLen==0){
		                layer.msg('请添加规格');
		                return;
		            }
		            var skeLen = $('#sku-wrap .sku-active').length;
		            if(skeLen==0){
		                layer.msg('请选择规格');
		                return;
		            }
		            $(this).hide();
		            $('#skuValueModel').show();
		        });
		        //  取消添加规格值按钮
		        $('#skuValueCancel').click(function () {
		            $('#skuValueName').val('');
		            $('#skuValueModel').hide();
		            $('#skuValueAdd').show();
		        });
		
		        //  添加规格值确认按钮
		        $('#skuValueConfirm').click(function () {
		            var skuName = $('.sku-choose').val();
		            fullName = pinyin.getFullChars(skuName);
		            var skuValueName = $('#skuValueName').val();
		            if(skuValueName == ''){
		                layer.msg('请输入规格名');
		                return;
		            }
		            //获取全写拼音（调用js中方法）
		            var fullValueName = pinyin.getFullChars(skuValueName);
		            //  判断规格值是否已存在
		            if(ifSkuExit(fullValueName)){
		                layer.msg('此规格已存在！');
		                return;
		            }
		            $('#sku-value-wrap').append('<input type="text" class="sku-value '+fullValueName+'" name="'+fullName+'" value="'+skuValueName+'" readonly><span value="'+skuValueName+'" class="delete-icon"></span>');
		            $('#skuValueName').val('');
		            $('#skuValueModel').hide();
		            $('#skuValueAdd').show();
		            combination();
		            $('#my-table').show();
		            combination();
		        });
		
		
		        function ifSkuExit(name){
		            var len = document.getElementsByClassName(name).length;
		            if(len==0){
		                return false;
		            }else {
		                return true;
		            }
		        }
                
		        // 组合数组
		        function combination () {
		            $('#tbody').html('');
		            $('#th').html('');
		            var arr = [];
		            var array = [];
		
		            var skuObjs = document.getElementsByClassName('sku-active');
		            for (var i = 0;i<skuObjs.length;i++){
		                var sku = skuObjs[i].value;
		                var py = pinyin.getFullChars(sku);
		                arr[i] = [];
		                var skuValueObjs = document.getElementsByName(py);
		                for(var j =0;j<skuValueObjs.length;j++){
		                    array[j] = [];
		                    array[j] = skuValueObjs[j].value;
		                    arr[i].push(array[j]);
		                }
		
		
					}
					arrayssk = [];
                    arrayssks = [];
					$(".sku-active").each(function(){
						var res = $(this).val();
						arrayssk.push(res);
					});
					$(".sku-choose").each(function(){
						var rew = $(this).val();
						arrayssks.push(rew);
					});
					// console.log(arrayssk);
                    // console.log(arrayssks);
                    $("#fuzhi").text(arrayssks);
					zon_arr = [];
                    shu = 1;
                    for(ssk=0;ssk<arrayssk.length;ssk++){
                        zon_arr[ssk] = {};
                        zon_arr[ssk]['id'] = ssk+1;
                        zon_arr[ssk]['name'] = arrayssk[ssk];
                        zon_arr[ssk]['sub'] = [];
                            for(ssk1=0;ssk1<arr[ssk].length;ssk1++){
                                zon_arr[ssk]['sub'][ssk1] = {};
                                zon_arr[ssk]['sub'][ssk1]['id'] = ""+(ssk+1)+""+""+(ssk1+1)+"";
                                zon_arr[ssk]['sub'][ssk1]['name'] = arr[ssk][ssk1];
                                shu++;
                            }
                    }
                    
                    // console.log(bool);
                    
                    // if(){}
                    // console.log(zon_arr);
                    return zon_arr;
                }
                // console.log(zon_arr);
                
                $('#sku-wrap').change(function () {
                    alert(1);
                    // $(".sku-choose").each(function(){
					// 	var rew = $(this).val();
					// 	arrayssks.push(rew);
					// });
                    // $("#fuzhi").text(arrayssks);
                });
		
		
		
		        // generateGroup([["红色","蓝色"],["X","XL"],["10m","20m"],["8g","16g"]]);
		

            // <!-- 规格 -->


//     layui.use('upload', function(){
//   var upload = layui.upload;
   
//   //执行实例
//   var uploadInst = upload.render({
//     elem: '#test1' //绑定元素
//     ,url: '/houtai/index/add_ok' //上传接口
//     ,done: function(res){
//       //上传完毕回调
//     }
//     ,error: function(){
//       //请求异常回调
//     }
//   });
// });
// layui.config({
//         base: '/static/lib/layui-v2.5.5/' //配置 layui 第三方扩展组件存放的基础目录
//     }).extend({
//         suk: 'sku'
//     }).use(['sku','jquery'],function(){
//         var sku = layui.sku;
//         var item = [{"id":1,"name":"颜色","sub":[{"id":1,"name":"黑"},{"id":2,"name":"白"},{"id":3,"name":"蓝"}]},{"id":2,"name":"尺寸","sub":[{"id":4,"name":"S"},{"id":5,"name":"M"},{"id":6,"name":"L"}]}];
//         var data = [{"ids":[{"1":"1"},{"2":"4"}],"price":986,"stock":23,"sku":"A941"}];
//             var SKU = sku.init({ id:'sku', item: item, data:data });

//             $("#_get").click(function(){
//                 var data = SKU.getData();
//                 var data2 = SKU.getItem();
//                 $("#data-html").html(JSON.stringify(data)+"<br></br>"+JSON.stringify(data2));
//             });
//      });

layui.config({
    base: '/static/lib/layui-v2.5.5/' //配置 layui 第三方扩展组件存放的基础目录
}).extend({
    suk: 'sku'
}).use(['form', 'layedit', 'laydate','upload','sku','jquery'], function () {
    var form = layui.form
    , sku = layui.sku
    , layer = layui.layer
    , upload = layui.upload
    , layedit = layui.layedit
    , laydate = layui.laydate;
    
    $('#huoqu').click(function () {
        qwe = $("#data-html").text();
        huixian = '';
        if(qwe!=''){
            huixian = JSON.parse(qwe);
        }
        console.log(qwe);
    var item = combination ();
    $("#sku").html(' ');
    bool = $("#sku-value-wrap input").length;
    if(bool==0){
        layer.msg('至少添加一个规格值', function(){
//关闭后的操作
},{
            // icon: 6,
            time: 3000,
            // end:function(){
            //     location.href='table_user';
            // }
        });
    }else{
        sp_guige(item,huixian);  
    }
    console.log(item);
    console.log(bool);
    
    });
    // console.log(xxoo);

    guige_chuan = '';
    kucun_chuan = '';
    function sp_guige(zhi,huixian){
            console.log(zhi);
            console.log(huixian);
                   
            var item = zhi;
            if(huixian==''){
                data = [];
            }else{
                data = huixian;
            }
            // data = [];
            // var item = [{"id":1,"name":"颜色","sub":[{"id":1,"name":"黑"},{"id":2,"name":"白"},{"id":3,"name":"蓝"}]},{"id":2,"name":"尺寸","sub":[{"id":4,"name":"S"},{"id":5,"name":"M"},{"id":6,"name":"L"}]},{"id":3,"name":"大小","sub":[{"id":7,"name":"小"},{"id":8,"name":"中"},{"id":9,"name":"大"}]}];
            // var data = [{"ids":[{"1":"1"},{"2":"4"}],"price":986,"stock":23,"sku":"A941"}];
            var SKU = sku.init({ id:'sku', item: item, data:data });
            function ssks(guige,kucun){
                guige_chuan = guige;
                kucun_chuan = kucun;
            }
            $("#sku").change(function(){
                var data = SKU.getData();
                var data2 = SKU.getItem();
                var guige = data;
                var kucun = data2;
                $("#data-html").html(JSON.stringify(data));
                // console.log(guige);
                ssks(guige,kucun);
            });
            $("#_get").click(function(){
                var data = SKU.getData();
                var data2 = SKU.getItem();
                var guige = data;
                var kucun = data2;
                $("#data-html").html(JSON.stringify(data));
                // $("#data-html").html(JSON.stringify(data)+"<br></br>"+JSON.stringify(data2));
                // console.log(guige);
                ssks(guige,kucun);
            });
            $("#tijiao").click(function(){
                var data = SKU.getData();
                var data2 = SKU.getItem();
                var guige = data;
                var kucun = data2;
                $("#data-html").html(JSON.stringify(data));
                // $("#data-html").html(JSON.stringify(data)+"<br></br>"+JSON.stringify(data2));
                // console.log(guige);
                ssks(guige,kucun);
            });
        }
        $(function () { 
            @if(!empty($row->guige_huixian))
            var item_jie = <?php echo $row->guige_huixian?>;
            var huixian_jie = <?php echo $row->shuju_huixian?>;
            
            console.log(huixian_jie);
            console.log(item_jie);
            // alert(1);
            sp_guige(item_jie,huixian_jie);  
            @endif
        });
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        

        //图片上传
        // var uploadInst = upload.render({
        //     elem: '#test1'
        //     // ,url: '/upload/'
        //     ,accept:'images'
        //     ,size:50000
        //     ,before: function(obj){

        //         obj.preview(function(index, file, result){

        //             $('#demo1').attr('src', result);
        //         });
        //     }
        //     ,done: function(res){
        //         //如果上传失败
        //         if(res.code > 0){
        //             return layer.msg('上传失败');
        //         }
        //         //上传成功
        //         var demoText = $('#demoText');
        //         demoText.html('<span style="color: #4cae4c;">上传成功</span>');

        //         var fileupload = $(".image");
        //         fileupload.attr("value",res.data.src);
        //         console.log(fileupload.attr("value"));
        //     }
        //     ,error: function(){
        //         //演示失败状态，并实现重传
        //         var demoText = $('#demoText');
        //         demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        //         demoText.find('.demo-reload').on('click', function(){
        //             uploadInst.upload();
        //         });
        //     }
        // });

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length == '') {
                    return '标题不能为空';
                }
            }
            , class: function (value) {
                if (value.length == '') {
                    return '请选择分类';
                }
            }
            , jieshao: function (value) {
                // layedit.sync(editIndex);
                if (value.length == '') {
                    return '介绍不能为空';
                }
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });
        var add_ok = {};
        //监听提交
        form.on('submit(demo1)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            // data.field = data.field;
            add_ok = data.field;
            add_ok['guige'] = JSON.stringify(guige_chuan);
            add_ok['kucun'] = JSON.stringify(kucun_chuan);
            if(add_ok['guige'] == '""'){
                add_ok['guige'] = '';
            }
            if(add_ok['kucun'] == '""'){
                add_ok['kucun'] = '';
            }
            if(add_ok['guige']==""){
                layer.msg('请添加商品规格',function(){},{
	            	icon: 6,
	            	time: 2000,
	            	// end:function(){
					// 	location.href='table_user';
					// }
                });
            }
            if(add_ok['kucun']==""){
                layer.msg('请添加商品规格库存',function(){},{
	            	icon: 6,
	            	time: 2000,
	            	// end:function(){
					// 	location.href='table_user';
					// }
                });
            }
            add_ok['add_html'] = $("#sku-wrap").html();
            add_ok['add2_html'] = $("#sku-value-wrap").html();
            // add_ok = JSON.stringify(add_ok);
            console.log(add_ok);
            console.log(guige_chuan);
            $.ajax({
                type: "POST",
                url: "/houtai/add_ok",
                dataType:'json',
                data: {add_ok},
                success:function(add_bool){
                    // add_bool = JSON.parse(add_bool);
                    console.log(add_bool);
                    
                if(add_bool['model']==4){
                    layer.msg(add_bool['think']+',两秒后自动跳转...',{
	            	icon: 6,
	            	time: 2000,
	            	end:function(){
						var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                        window.parent.location.reload();
					}
	            });
				}else if(add_bool['model']==6){
                    layer.msg(add_bool['think']+',两秒后自动跳转...',{
	            	icon: 6,
	            	time: 2000,
	            	end:function(){
						var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                        window.parent.location.reload();
					}
	            });
				}else{
                    layer.msg(add_bool['think'], {icon: 5});
				}
            }});
            return false;
        });

        //表单初始赋值
       


    });
    $("#img_xian").mouseover(function(){
        layer.tips('点击查看图片', '#img_xian');
    });
    $("#img_xian").click(function(){
        s = $('#img_tu').html();
        console.log(s);
        layer.open({
        type: 1,
        area: ['700px', '500px'],
        title: false,
        closeBtn: 0,
        shadeClose: true,
        skin: '',
        content: s
        });
    });
</script>

<!-- guige -->

</body>
</html>